
#ifndef _OTP_H
#define _OTP_H

#define OTP_SUCC 0
#define OTP_ERR 1

//
typedef struct {
	const char *secret;
	int secret_length;
	long counter;
} hotp_ctx;

//
void hotp_init  (hotp_ctx *ctx, const char *secret, long counter);
void hotp_set_secret(hotp_ctx *ctx, const char *secret, int secret_length);
void hotp_gen   (hotp_ctx *ctx, char *token);
int hotp_verify (hotp_ctx *ctx, const char *token);
void hotp_gen2  (hotp_ctx *ctx, char *token, long counter);
int hotp_verify2(hotp_ctx *ctx, const char *token, long counter);

//
typedef struct {
	const char *secret;
	int secret_length;
	int window;
	int interval;
} totp_ctx;

//
void totp_init  (totp_ctx *ctx, const char *secret, int window, int interval);
void totp_set_secret(totp_ctx *ctx, const char *secret, int secret_length);
void totp_gen   (totp_ctx *ctx, char *token);
int totp_verify (totp_ctx *ctx, const char *token);
void totp_gen2  (totp_ctx *ctx, char *token, long timestamp);
int totp_verify2(totp_ctx *ctx, const char *token, long timestamp);

//
int otp_convert_secret(const char *secret, const char *format, char *binary, int *binary_length);

#endif /* _OTP_H */

